//
// Created by zhouyi on 2019-11-28.
//

#ifndef TESTFFMPEG_ENJOYPLAYER_H
#define TESTFFMPEG_ENJOYPLAYER_H

#include <pthread.h>
#include "JavaCallHelper.h"
#include "VideoChannel.h"
//#include "AudioChannel.h"
#include <android/native_window_jni.h>

extern "C" {
#include <libavformat/avformat.h>

};


class EnjoyPlayer {
    friend void *asyncPrepare_t(void *args);

    friend void *asyncStart_t(void *args);

public:
    EnjoyPlayer(JavaCallHelper *pHelper);

public:

    void setDataSource(const char *path_);

    void setWindow(ANativeWindow *window);

    void prepare();

    void start();


private:
    char *path;
    pthread_t prepareTask;
    JavaCallHelper *helper;

    int64_t duration;

    VideoChannel *videoChannel;
//    AudioChannel *audioChannel;

    bool isPlaying = 0;
    pthread_t startTask;

    AVFormatContext *avFormatContext;
    ANativeWindow *window = 0;


private:

    void _prepare();

    void _start();
};


#endif //TESTFFMPEG_ENJOYPLAYER_H
